package leetcode.code0204;

public class Solution1 extends Solution204 {

	@Override
	public int countPrimes(int n) {
		if (n < 3) {
			return 0;
		}
		int[] isPrime = new int[n];
		int range = 1;
		isPrime[0] = 2;
		for (int i = 3; i < n; i += 2) {
			if (isPrime[i] == 0) {
				isPrime[range++] = i;
			}
			for (int j = 0; j < range && i * isPrime[j] < n; j++) {
				isPrime[i * isPrime[j]] = 1;
				if (i % isPrime[j] == 0) {
					break;
				}
			}
		}
		return range;
	}

	public static void main(String[] args) {
		Solution1 so = new Solution1();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
	}

}
